﻿using Microsoft.Xna.Framework;

namespace Project1
{
    public class MovableObject : BoundedObject
    {
        public MovableObject(Game1 g, string asset, Vector2 position) :
            base(g, asset, position)
        {
            Velocity = new Vector2(0, 0);
            Acceleration = new Vector2(0, 0);
        }

        // Have to wrap velocity set/get because 
        public Vector2 Velocity { get; set; }
        public Vector2 Acceleration { get; set; }
        public float? TerminalVelocity { get; set; }

        public override void Update(GameTime gametime)
        {
            Position += gametime.ElapsedGameTime.Milliseconds / 1000.0f * Velocity;
            Velocity += gametime.ElapsedGameTime.Milliseconds / 1000.0f * Acceleration;
            
            // Limit maximum object speed
            if (TerminalVelocity.HasValue && Velocity.Length() > TerminalVelocity)
            {
                Velocity *= TerminalVelocity.Value / Velocity.Length();
            }
        }
    }
}